package com.aaron.kjviewutils.footballleague;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.aaron.kjviewutils.R;
import com.aaron.kjviewutils.glide.GlideCircleTransform;
import com.aaron.kjviewutils.glide.WebpDataModel;
import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：Aaron on 2017/2/20 11:50
 * 邮箱：kaijin.fang@edianniu.com
 */
public class LleagueAdapter extends RecyclerView.Adapter<LleagueAdapter.LleagueViewHolder> {

    private Activity aty;
    private List<FootBallLleagueBean.Lleagues.Lleague.Team> datas;

    public LleagueAdapter(Activity aty, List<FootBallLleagueBean.Lleagues.Lleague.Team> datas)
    {
        this.aty = aty;
        this.datas = datas;
    }

    @Override
    public LleagueViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(aty).inflate(R.layout.item_lleague, parent, false);
        return new LleagueViewHolder(view);
    }

    @Override
    public void onBindViewHolder(LleagueViewHolder holder, int position) {

        if(null!=datas&&!datas.isEmpty())
        {
            FootBallLleagueBean.Lleagues.Lleague.Team team = datas.get(position);
            Glide.with(aty).load(new WebpDataModel(team.teamLogoUrl)).centerCrop().transform(new GlideCircleTransform(aty)).placeholder(R.mipmap.ic_launcher).into(holder.lleagueIcon);
            holder.lleagueTag.setText(team.teamNameCn);
        }
    }

    @Override
    public int getItemCount() {
        return (null==datas)?0:datas.size();
    }

    public class LleagueViewHolder extends RecyclerView.ViewHolder
    {

        @Bind(R.id.lleagueTag)
        TextView lleagueTag;
        @Bind(R.id.lleagueIcon)
        ImageView lleagueIcon;

        public LleagueViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
